import axios from 'axios'
import { tansParams } from '@/utils/ruoyi'
import JsonBig from 'json-bigint'
import qs from 'qs'
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
const service = axios.create({
  baseURL: import.meta.env.VITE_APP_BASE_API,
  timeout: 10000,
  paramsSerializer:params => {
    return qs.stringify(params, {arrayFormat: 'repeat'});
  },
  transformResponse: [data => {
    const json = JsonBig({
      storeAsString: true
    })
    try {
      return json.parse(data)
    }
    catch
    {
      return data;
    }
  }],
})
service.interceptors.request.use(config => {
  if (config.method === 'get' && config.params) {
    let url = config.url + '?' + tansParams(config.params);
    url = url.slice(0, -1);
    config.params = {};
    config.url = url;
  }
  return config
}, error => {
  Promise.reject(error)
})
service.interceptors.response.use(res => {
   return Promise.resolve(res);
}, async function(error) {
})


export default service
